<template>
  <div>
    <el-form
      :model="ruleForm"
      :rules="rules"
      ref="ruleForm"
      label-width="100px"
      class="demo-ruleForm"
    >
      <el-row>
        <el-col :span="12" :offset="0">
          <el-form-item label="企业名称" prop="brandName">
            <el-input v-model="ruleForm.brandName"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="企业法人" prop="boss">
            <el-input v-model="ruleForm.boss"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12" :offset="0">
          <el-form-item label="注册资本" prop="capital">
            <el-input v-model="ruleForm.capital"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="所属行业" prop="industry">
            <el-input v-model="ruleForm.industry"></el-input>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12" :offset="0">
          <el-form-item label="企业LOGO" prop="brandLogo">
            <img-upload v-m-model="ruleForm.brandLogo" />
          </el-form-item>
        </el-col>
        <el-col :span="12" :offset="0">
          <el-form-item label="营业执照" prop="license">
            <img-upload @update="handleImg($event, 'license')" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-form-item label="企业位置" prop="address">
        <el-row>
          <el-col :span="18" :offset="0">
            <el-input type="text" v-model="ruleForm.address"></el-input>
          </el-col>
          <el-col :span="4" :offset="0">
            <el-button type="primary" size="default" @click="drawer = true"
              >点击选址</el-button
            >
          </el-col>
        </el-row>
      </el-form-item>
      <el-form-item label="企业介绍" prop="intro">
        <RichEditor v-m-model="ruleForm.intro" />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="submitForm('ruleForm')"
          >立即创建</el-button
        >
        <el-button @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
    <el-drawer
      title="地图选址"
      :visible.sync="drawer"
      direction="btt"
      size="60%"
    >
      <GodMap @send-address="handleImg($event, 'address')" />
    </el-drawer>
  </div>
</template>
<script>
import GodMap from "@/components/god-map.vue";
import RichEditor from "@/components/rich-editor.vue";
import { companyPost } from "@/api/job";
export default {
  components: {
    GodMap,
    RichEditor,
  },
  data() {
    return {
      ruleForm: {
        brandName: "万峰互联",
        boss: "卢老师",
        capital: "2000000万",
        industry: "服务业",
        brandLogo: "",
        license: "",
        address: "",
        intro: "",
      },
      rules: {
        brandName: [
          { required: true, message: "请输入公司名称", trigger: "blur" },
        ],
        boss: [{ required: true, message: "请输入企业法人", trigger: "blur" }],
        capital: [
          { required: true, message: "请输入注册资本", trigger: "blur" },
        ],
        industry: [{ required: true, message: "请输入行业", trigger: "blur" }],
        brandLogo: [{ required: true, message: "请上传LOGO", trigger: "blur" }],
        license: [
          { required: true, message: "请上传营业执照", trigger: "blur" },
        ],
        address: [{ required: true, message: "请选择地址", trigger: "blur" }],
        intro: [{ required: true, message: "请填写简介", trigger: "blur" }],
      },
      cateList: [],
      drawer: false,
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          console.log(this.ruleForm);
          companyPost(this.ruleForm);
        } else {
          console.log("error submit!!");
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
    handleImg(url, key) {
      console.log(url, key);
      this.ruleForm[key] = url;
    },
  },
};
</script>
